package org.dromara.crawler.mongo.mongoservice.impl;

import cn.hutool.core.util.ObjectUtil;
import com.mongoplus.conditions.query.LambdaQueryChainWrapper;
import com.mongoplus.service.impl.ServiceImpl;

import org.dromara.crawler.domain.bo.DataCollectionBo;
import org.dromara.crawler.mongo.mongodomain.CNN;
import org.dromara.crawler.mongo.mongodomain.Wiki;

import org.dromara.crawler.mongo.mongodomain.XinHuaNet;
import org.dromara.crawler.mongo.mongoservice.WikiService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WikiServiceImpl extends ServiceImpl<Wiki> implements WikiService {
    @Override
    public Wiki queryById(String id) {
        return this.getById(id);
    }


    @Override
    public List<Wiki> getAll() {
        return this.list();
    }

    @Override
    public LambdaQueryChainWrapper createWrapper(DataCollectionBo dataCollectionBo) {
        LambdaQueryChainWrapper<Wiki> wrapper = this.lambdaQuery();
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getEventFirstLevel()), Wiki::getEventFirstLevel, dataCollectionBo.getEventFirstLevel());
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getEventSecondLevel()), Wiki::getEventSecondLevel, dataCollectionBo.getEventSecondLevel());
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getKeyword()), Wiki::getKeyword, dataCollectionBo.getKeyword());
        wrapper.gte(ObjectUtil.isNotEmpty(dataCollectionBo.getStartTime()), Wiki::getTime, dataCollectionBo.getStartTime());
        wrapper.lte(ObjectUtil.isNotEmpty(dataCollectionBo.getEndTime()), Wiki::getTime, dataCollectionBo.getEndTime());
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getTitle()), Wiki::getTitle, dataCollectionBo.getTitle());
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getStatus1()), Wiki::getStatus1, dataCollectionBo.getStatus1());
        wrapper.like(ObjectUtil.isNotEmpty(dataCollectionBo.getStatus2()), Wiki::getStatus2, dataCollectionBo.getStatus2());
        wrapper.orderByDesc(Wiki::getCrawlTime);
        return wrapper;
    }

    @Override
    public List<Wiki> queryByCondition(DataCollectionBo bo) {
        LambdaQueryChainWrapper<Wiki> wrapper = this.lambdaQuery();
        wrapper.like(ObjectUtil.isNotEmpty(bo.getEventFirstLevel()), Wiki::getEventFirstLevel, bo.getEventFirstLevel());
        wrapper.like(ObjectUtil.isNotEmpty(bo.getEventSecondLevel()), Wiki::getEventSecondLevel, bo.getEventSecondLevel());
        wrapper.like(ObjectUtil.isNotEmpty(bo.getKeyword()), Wiki::getKeyword, bo.getKeyword());
        wrapper.gte(ObjectUtil.isNotEmpty(bo.getStartTime()), Wiki::getTime, bo.getStartTime());
        wrapper.lte(ObjectUtil.isNotEmpty(bo.getEndTime()), Wiki::getTime, bo.getEndTime());
        wrapper.orderByDesc(Wiki::getCrawlTime);
        return wrapper.list();
    }


}
